﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using InstituteManager.Bussiness;
using InstituteManager.Data;

namespace InstituteManager
{
    public partial class viewCompetition : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["compe"] != null){
                int CompeId = int.Parse(Request.QueryString["compe"]);
                tbl_Competition obj = CompetitionBL.getById(CompeId);
                lblCompetitionName.Text = obj.CompetitionName;
                lblStartDate.Text = obj.StartDate.Value.ToString("d");
                lblEndDate.Text = obj.EndDate.Value.ToString("d");
                lblCondition.Text = obj.Condition;
                lblStaffManager.Text = obj.tbl_Staff.StaffName;
                lblAwardName.Text = obj.tbl_Award.AwardName;
                lblWorth.Text = obj.tbl_Award.Worth.ToString();
                lblDescription.Text = obj.tbl_Award.Description;
                lblSubmission.Text = CompetitionBL.getNumberOfCompetitionPosting(CompeId).ToString();
                if (obj.StartDate > DateTime.Now)
                    lblCompetitionType.Text = "Upcoming Competition";
                if (obj.StartDate < DateTime.Now && obj.EndDate > DateTime.Now)
                    lblCompetitionType.Text = "Ongoing Competition";

                if (CompetitionBL.isAwardIssued(CompeId))
                {

                    tbl_Posting posting = PostingBL.getById(CompetitionBL.getPostingAwarded(CompeId).PostingId);
                    lblStudentName.Text = posting.tbl_Student.StudentName;
                    lblStudentPhone.Text = posting.tbl_Student.StudentPhone;
                    if (posting.tbl_Student.DOB != null)
                        lblDOB.Text = posting.tbl_Student.DOB.Value.ToString("d");
                    lblAddress.Text = posting.tbl_Student.Address;
                    lblEmail.Text = posting.tbl_Student.Email;

                    lblPostingName.Text = posting.PostingName;
                    if (posting.PostDate != null)
                        lblPostDate.Text = posting.PostDate.Value.ToString("d");
                    lblPostDescription.Text = posting.Description;
                    lblPrice.Text = posting.Price.ToString();
                    lblRemark.Text = posting.Remark;
                    imgPosting.ImageUrl = posting.ImageUrl;
                   

                    pnlStudentAwarded.Visible = true;
                    lblCompetitionType.Text = "Competitions are Awarded";
                }
            }

        }
    }
}